package com.wzdigit.wms.wms.service.core;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.framework.Shift;
import com.wzdigit.wms.basic.client.request.transfer.SingleStepTransferReq;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.basic.LocationApiResponse;
import com.wzdigit.wms.basic.client.response.transfer.HeapAndMergerResponse;
import com.wzdigit.wms.basic.client.response.transfer.TransferTaskScanSnResponse;
import com.wzdigit.wms.basic.domain.dtos.inventory.BindWarehousePositionDto;
import com.wzdigit.wms.basic.domain.dtos.inventory.SnInforDto;
import com.wzdigit.wms.basic.domain.dtos.inventory.UpdateInventoryInputDto;
import com.wzdigit.wms.basic.domain.inventory.*;
import com.wzdigit.wms.basic.enums.*;
import com.wzdigit.wms.basic.mapper.core.inventory.*;
import com.wzdigit.wms.basic.mapper.core.inventory.manager.GoodsManagerMapper;
import com.wzdigit.wms.basic.service.code.InventoryService;
import com.wzdigit.wms.basic.util.StringUtils;
import com.wzdigit.wms.common.entity.StatusCode;
import com.wzdigit.wms.common.utils.MyListUtil;
import com.wzdigit.wms.wms.service.basic.LocationService;
import net.dreamlu.mica.core.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    
    @Autowired
    private GoodsTempMapper goodsTempMapper;

    @Autowired
    private GoodsHisMapper goodsHisMapper;

    @Autowired
    private GoodsPkgMapper goodsPkgMapper;

    @Autowired
    private GoodsLogMapper goodsLogMapper;

    @Autowired
    private GoodsManagerMapper goodsManagerMapper;

    @Autowired
    private LocationService locationService;

    @Autowired
    private InventoryService inventoryService;


    public GoodsMapper getGoodsMapper() {
        return this.goodsMapper;
    }

    public GoodsPkgMapper getGoodsPkgMapper() {
        return this.goodsPkgMapper;
    }

    public GoodsHisMapper getGoodsHisMapper() {
        return this.goodsHisMapper;
    }

    public GoodsTempMapper getGoodsTempMapper() {
        return this.goodsTempMapper;
    }

    /**
     * 根据 SN 获取 货品详细信息
     *
     * @param sn sn条码
     * @return
     */
    public Goods selectBySn(String sn) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GOODS_SN", sn);
        Goods item = this.goodsMapper.selectOne(queryWrapper);
        return item;
    }

    /**
     * 根据 SN 获取 货品详细信息[初始化入库使用]
     *
     * @param sn sn条码
     * @return
     */
    public GoodsTemp selectTempGoodsBySn(String sn) {
        QueryWrapper<GoodsTemp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GOODS_SN", sn);
        List<GoodsTemp> items = this.goodsTempMapper.selectList(queryWrapper);
        if (items.size() == 0)
            return null;
        return items.get(0);
    }

    /**
     * 通过 sn列表 获取货品详细信息
     *
     * @param listSn
     * @return
     */
    public List<Goods> selectListByListSn(List<String> listSn) {
        if (listSn != null && listSn.size() > 0) {
            QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("GOODS_SN", listSn);
            List<Goods> items = this.goodsMapper.selectList(queryWrapper);
            return items;
        }
        return new ArrayList<Goods>(0);
    }
    
    /**
     * 通过 id列表 获取货品详细信息
     * @param idList
     * @return
     */
    public List<Goods> selectListByIdList(List<Integer> idList) {
        if (idList != null && idList.size() > 0) {
            QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("GOODS_ID", idList);
            List<Goods> items = this.goodsMapper.selectList(queryWrapper);
            return items;
        }
        return new ArrayList<Goods>(0);
    }

    /**
     * 通过 sn条码 获取堆板货品信息
     *
     * @param sn
     * @return
     */
    public Result<HeapAndMergerResponse> selectHeapAndMergerBySn(String sn) {
        HeapAndMergerResponse heapAndMergerResponse = goodsMapper.selectHeapBySn(sn);
        if (heapAndMergerResponse==null){
            Shift.fatal(StatusCode.SERVER_NOT_FOUND_ERROR,"没有找到对应条码的商品信息");
        }
        if (heapAndMergerResponse.getStatus()!= GoodsStatusEnum.WAIT_UP.getCode()
                &&heapAndMergerResponse.getStatus()!=GoodsStatusEnum.HAS_UP.getCode()
                &&heapAndMergerResponse.getStatus()!=GoodsStatusEnum.WAIT_DOWM.getCode()){
            Shift.fatal(StatusCode.NOT_GOOD_SN,"堆板货品必须为待上架、已上架、已下架");
        }
        return new Result(true,"查询成功",heapAndMergerResponse);
    }

    /**
     * 货品建档
     *
     * @param itemPkg 货品包装信息(可空）
     * @param item
     * @return
     */
    public Integer insertNewGoods(Goods item, GoodsPkg itemPkg) {
        //1. 如果包装不为空
        if (itemPkg != null) {
            //1. 获取包装信息
            QueryWrapper<GoodsPkg> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("PKG_SN", itemPkg.getPkgSn());
            GoodsPkg goodsPkg = this.goodsPkgMapper.selectOne(queryWrapper);
            if (goodsPkg == null) {
                this.goodsPkgMapper.insert(itemPkg);
            }
        }
        //2. 添加条码信息
        item.setPkgId(item.getPkgId());
        this.goodsMapper.insert(item);
        return item.getGoodsId();
    }

    /**
     * 货品建档
     *
     * @param itemPkg
     * @param items
     */
    public void insertNewGoods(List<Goods> items, GoodsPkg itemPkg) {
        //1. 如果包装不为空
        if (itemPkg != null) {
            //1. 获取包装信息
            QueryWrapper<GoodsPkg> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("PKG_SN", itemPkg.getPkgSn());
            GoodsPkg goodsPkg = this.goodsPkgMapper.selectOne(queryWrapper);
            if (goodsPkg == null) {
                this.goodsPkgMapper.insert(itemPkg);
            }
        }
        for (Goods item : items) {
            item.setPkgId(item.getPkgId());
            this.goodsMapper.insert(item);
        }
    }

    /**
     * 更新货品
     *
     * @param itemPkg
     * @param item
     */
    public void updateGoods(GoodsPkg itemPkg, Goods item) {
        if (itemPkg != null) {
            this.goodsPkgMapper.updateById(itemPkg);
        }
        this.goodsMapper.updateById(item);
    }

    public boolean updateGoods(Goods item) {
        return this.goodsMapper.updateById(item) > 0;
    }

    /**
     * 添加操作记录
     *
     * @param input
     * @return
     */
    public boolean insertGoodsLog(GoodsLog input) {
        return this.goodsLogMapper.insert(input) > 0;
    }

    public boolean insertGoods(Goods input) {
        return this.goodsMapper.insert(input) > 0;
    }

    /**
     * 校验sn是否存在
     *
     * @param sn
     * @return
     */
    public boolean checkExist(String sn) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GOODS_SN", sn);
        Integer cnt = this.goodsMapper.selectCount(queryWrapper);
        return cnt > 0;
    }

    /**
     * 校验 sn 可用性
     *
     * @param sn
     * @return
     */
    public boolean checkUsable(String sn, String opCode) {
        Goods item = this.selectBySn(sn);
        if (item == null)
            return false;
        if (item.getQaStatus() == QaStatusEnum.WAIT.getCode())//|| item.getQaStatus() == QaStatusEnum.UNQUALIFIED.getCode()
            return false;
        return true;
    }

    /**
     * 校验 sn QA状态(品质状态)
     *
     * @param sn
     * @return
     */
    public boolean checkQaStatus(String sn, String orderType) {
        Goods item = this.selectBySn(sn);
        if (item == null)
            return false;
//        if (orderType == OrderTypeEnum.ASN) {
//            return true;
//        } else if (orderType == OrderTypeEnum.GDN) {
//            if (item.getQaStatus() == QaStatusEnum.WAIT.getCode() || item.getQaStatus() == QaStatusEnum.UNQUALIFIED.getCode())
//                return false;
//        }
        return true;
    }

    /**
     * SN查询
     *
     * @param sn
     * @param type
     * @return
     */
    public List<SnInforDto> selectSnInfosBySn(String sn, SnScanTypeEnum type) {
        List<SnInforDto> list = null;
        if (type == SnScanTypeEnum.SELECT_SN) { //单sn查询
            list = goodsManagerMapper.selectSnsBySnOrPalletId(sn, null);
        } else {
            //1. 根据sn获取到包装表的ID
            Integer pkgId = goodsMapper.selectPkgIdBySn(sn);
            if (pkgId != null) {
                //2. 根据包装ID获取包装URL
                String url = goodsPkgMapper.selectUrlById(pkgId);
                if (StringUtils.isNotNull(url)) {
                    //3. 路径用'_'分开, 取第一位  最上层的ID
                    Integer palletId = Integer.valueOf(url.substring(0, url.indexOf("_")));
                    //4. 通过路径获取 所有的 sn
                    list = goodsManagerMapper.selectSnsBySnOrPalletId(null, palletId);
                }
            } else {
                Shift.fatal("该SN没有整板外包装");
            }
        }
        return list;
    }

    /**
     * 库位绑定
     * @throws Exception 
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void bindWareHousePosition(BindWarehousePositionDto input, String userName) throws Exception {
    	// 根据sn批量查找goods
    	QueryWrapper<Goods> queryWrapper = new QueryWrapper<Goods>();
    	List<String> allGoodsSns = input.goodsSns;
    	List<Goods> wmsgoodList = null;
    	if(allGoodsSns.size() >= 1000) {
    		wmsgoodList = new ArrayList<>(allGoodsSns.size());
    		List<List<String>> snListList = MyListUtil.splitList(allGoodsSns, 999);
    		for (List<String> snList : snListList) {
    			queryWrapper.clear();
    			queryWrapper.in("GOODS_SN", snList);
    			wmsgoodList.addAll(goodsMapper.selectList(queryWrapper));
    		}
    	} else {
			queryWrapper.in("GOODS_SN", allGoodsSns);
			wmsgoodList = goodsMapper.selectList(queryWrapper);
    	}

        // 判断是否全部SN状态都为“待上架”
        if (wmsgoodList.stream().filter(c -> !c.getStatus().equals(GoodsStatusEnum.WAIT_UP.getCode()) &&
        		!c.getStatus().equals(GoodsStatusEnum.WAIT_DOWM.getCode()))
                .count() > 0) {
            Shift.fatal("不允许上架！");
        }

        // 得出所有仓库id,个数大于1证明有不同的仓库
        if (wmsgoodList.stream().map(Goods::getWhsId).distinct().collect(Collectors.toList()).size() > 1) {
            Shift.fatal("当前这批SN存在不同仓库的数据");
        }

        // 仓库下的库位是否包含传进来的库位
        List<LocationApiResponse> locsEs = locationService.getLocationByWhs(wmsgoodList.get(0).getWhsId());
        if (locsEs.stream().filter(c -> c.getLocId().equals(input.getLocId())).count() == 0) {
            Shift.fatal("当前库位与SN所属仓库不一致");
        }

        Date date = new Date();
        String reason = "SN绑定库位";
        BigDecimal zero = BigDecimal.ZERO;
        String opCode = OpCodeEnum.PUTON.getCode();
        int goodsStatus = GoodsStatusEnum.HAS_UP.getCode();
        int invTransStatus = InvTransStatusEnum.FINISHED.getCode();

        for (Goods goods : wmsgoodList) {
            String goodsOriginalJson = JSON.toJSONString(goods);    // 原先的json

            goods.setModifyTime(date);
            goods.setModifyUser(userName);
            goods.setStatus(goodsStatus);
            goods.setLocId(input.getLocId());
            if (input.getDeletePkg() != null && input.getDeletePkg()) {
                goods.setPkgId(null);
            }
            goodsMapper.updateLocIdAndPkgIdAndStatusById(goods);

            String goodsJson = JSON.toJSONString(goods);            // 更新后的json
            String jsonString = "未更新的:" + goodsOriginalJson + ",更新的:" + goodsJson;

            // 写入SN操作日志
            GoodsLog goodsLog = new GoodsLog();
            goodsLog.setInvTransId(0);
            goodsLog.setGoodsSn(goods.getGoodsSn());
            goodsLog.setOpCode(opCode);
            goodsLog.setReason(reason);
            goodsLog.setUpdateContent(jsonString);
            goodsLog.setOperator(userName);
            goodsLog.setCreateUser(userName);
            goodsLog.setCreateTime(date);
            insertGoodsLog(goodsLog);
        }

        // 根据传入的sn集合查询，根据仓库，货主，货品，工厂代码，供应商，批次号，库存性质，品质状态进行分组统计
        Map<String, List<Goods>> collect = wmsgoodList.stream().collect(Collectors.groupingBy(t ->
                (t.getWhsId() + "#" + t.getLocId() + "#" + t.getOwner() + "#" +
                        t.getSkuId() + "#" + t.getFactory() + "#" + t.getVendorId() + "#" +
                        t.getLotno() + "#" + t.getInvAttr() + "#" + t.getQaStatus() + "#"), Collectors.toList()));
        for (String key : collect.keySet()) {
            List<Goods> goodsCollect = collect.get(key);

            BigDecimal qty = goodsCollect.stream().map(t -> t.getQty()).reduce(zero, BigDecimal::add);

            UpdateInventoryInputDto toInv = new UpdateInventoryInputDto();
            toInv.setLocId(input.getLocId());
            toInv.setWhsId(goodsCollect.get(0).getWhsId());
            toInv.setOwner(goodsCollect.get(0).getOwner());
            toInv.setSkuId(goodsCollect.get(0).getSkuId());
            toInv.setFactory(goodsCollect.get(0).getFactory());
            toInv.setVendorId(goodsCollect.get(0).getVendorId());
            toInv.setLotNo(goodsCollect.get(0).getLotno());
            toInv.setInvAttr(goodsCollect.get(0).getInvAttr());
            toInv.setQaStatus(goodsCollect.get(0).getQaStatus());
            toInv.setUnit(goodsCollect.get(0).getUnit());
            toInv.setQty(qty);
            toInv.setPreInQty(zero);
            toInv.setPreOutQty(zero);
            toInv.setHoldQty(zero);
            toInv.setPreAlocQty(zero);
            toInv.setAlocQty(zero);
            toInv.setOperator(userName);

            UpdateInventoryInputDto fmInv = new UpdateInventoryInputDto();
            BeanUtil.copyNonNull(toInv, fmInv);
            fmInv.setQty(qty.negate());
            fmInv.setLocId(null);

            InvTrans invTrans = new InvTrans();
            invTrans.setOpCode(opCode);
            invTrans.setDocType(" ");
            invTrans.setDocNo(" ");
            invTrans.setDocLineNo(" ");
            invTrans.setTrsnNo(" ");
            invTrans.setTrsnLineNo(" ");
            invTrans.setStatus(invTransStatus);
            invTrans.setTransTime(date);
            invTrans.setOperator(userName);
            invTrans.setTransQty(qty);
            invTrans.setCreateTime(date);
            invTrans.setCreateUser(userName);

            inventoryService.inventoryTransfer(fmInv, toInv, invTrans);
        }
    }

    /**
     * 解绑
     *
     * @param goodsSns
     * @return
     * @throws Exception 
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void unBindWareHousePosition(List<String> goodsSns, String userName) throws Exception {
        try {
            Date date = new Date();
            String reason = "SN绑定解绑";
            BigDecimal zero = BigDecimal.ZERO;
            String opCode = OpCodeEnum.PUTOFF.getCode();

            //根据sn查数据
            QueryWrapper<Goods> queryWrapper = new QueryWrapper<Goods>();
            queryWrapper.in("GOODS_SN", goodsSns);
            List<Goods> wmsgoodList = goodsMapper.selectList(queryWrapper);
            for (Goods goods : wmsgoodList) {
                String goodsOriginalJson = JSON.toJSONString(goods);//原先的json

                goods.setLocId(null);
                goods.setModifyTime(date);
                goods.setModifyUser(userName);
                goodsMapper.updateLocIdAndPkgIdAndStatusById(goods);

                String goodsJson = JSON.toJSONString(goods);        //更新后的json
                String jsonString = "未更新的:" + goodsOriginalJson + ",更新的:" + goodsJson;

                //写入SN操作日志
                GoodsLog goodsLog = new GoodsLog();
                goodsLog.setInvTransId(0);
                goodsLog.setGoodsSn(goods.getGoodsSn());
                goodsLog.setOpCode(opCode);
                goodsLog.setReason(reason);
                goodsLog.setUpdateContent(jsonString);
                goodsLog.setOperator(userName);
                goodsLog.setCreateUser(userName);
                goodsLog.setCreateTime(date);
                insertGoodsLog(goodsLog);
            }

            //根据传入的sn集合查询，根据仓库，货主，货品，工厂代码，供应商，批次号，库存性质，品质状态进行分组统计
            List<UpdateInventoryInputDto> goodsUpdateList = goodsMapper.selectUpdateList(goodsSns);
            for (UpdateInventoryInputDto updateLocInventoryInputDto : goodsUpdateList) {
                updateLocInventoryInputDto.setLocId(updateLocInventoryInputDto.getLocId());//设置库位
                updateLocInventoryInputDto.setQty(updateLocInventoryInputDto.getQty().negate());
                updateLocInventoryInputDto.setPreInQty(zero);
                updateLocInventoryInputDto.setPreOutQty(zero);
                updateLocInventoryInputDto.setHoldQty(zero);
                updateLocInventoryInputDto.setAlocQty(zero);
                updateLocInventoryInputDto.setPreAlocQty(zero);
                updateLocInventoryInputDto.setOperator(userName);

                UpdateInventoryInputDto old = new UpdateInventoryInputDto();
                BeanUtil.copyNonNull(updateLocInventoryInputDto, old);
                old.setQty(updateLocInventoryInputDto.getQty());
                old.setLocId(null);

                //(先减少)调更新库存服务
                inventoryService.updateLocInventroy(updateLocInventoryInputDto);

                //后增加
                //原库存减少
                inventoryService.updateLocInventroy(old);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 根据 货品ID 查询货品信息
     *
     * @param goodsId
     * @return
     */
    public Goods selectByGoodsId(Integer goodsId) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GOODS_ID", goodsId);
        Goods item = this.goodsMapper.selectOne(queryWrapper);
        return item;
    }

    public Integer getGoodsPkgSequences() {
        return this.goodsPkgMapper.selectSeuences();
    }


    /**
     * 根据sn和仓库ID查询
     *
     * @param whsId
     * @param sn
     * @return
     */
    public Goods selectByGoodsSnAndWhsId(Integer whsId, String sn) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GOODS_SN", sn).eq("WHS_ID", whsId);
        Goods goods = goodsMapper.selectOne(queryWrapper);
        return goods;
    }


    /**
     * 根据实体更新
     *
     * @param goods
     * @return
     */
    public Integer updateStatusByGoods(Goods goods) {
        int row = goodsMapper.updateById(goods);
        return row;
    }

    public List<Goods> selectGoodsByHisSn(List<String> snList) {
        return this.goodsHisMapper.selectGoodsByHisSn(snList);
    }
    public List<Goods> selectGoodsByHisSn(String... snArray) {
    	List<String> snList = Arrays.asList(snArray);
        return this.goodsHisMapper.selectGoodsByHisSn(snList);
    }

//    public List<TransferTaskScanSnResponse> getOnConditionSingleStepTransfer(SingleStepTransferReq singleStepTransferReq, Integer waitUpCode, Integer hasUpCode) {
    public List<TransferTaskScanSnResponse> getOnConditionSingleStepTransfer(SingleStepTransferReq singleStepTransferReq, List<Integer> allowStatusList) {

        List<TransferTaskScanSnResponse> taskScanSnResponseList = goodsMapper.getOnConditionSingleStepTransfer(singleStepTransferReq, allowStatusList);

        return taskScanSnResponseList;
    }

    /**
     * 根据实体，主键集合更新货品信息
     *
     * @param goodsIdList
     * @param goods
     * @return
     */
    public Integer updateGoodsList(List<Integer> goodsIdList, Goods goods) {

        //创建类型的条件构造器
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.in("GOODS_ID", goodsIdList);

        int updateRow = goodsMapper.update(goods, wrapper);
        return updateRow;
    }

    /**
     * 根据送检单号查询
     *
     * @param inspNo
     * @return
     */
    public List<Goods> selectByGoodsByOqc(String inspNo) {

        //创建类型的条件构造器
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.eq("INSP_NO", inspNo);
        List<Goods> goodsList = goodsMapper.selectList(wrapper);

        return goodsList;
    }
    
    /**
     * 获取工单号
     * 
     * @param listSn
     * @return
     */
    public List<String> selectPrdWoListByListSn(List<String> listSn) {
        if (listSn != null && listSn.size() > 0) {
            List<String> prdWoList = this.goodsMapper.selectPrdWoListByListSn(listSn);
            return prdWoList;
        }
        return new ArrayList<String>(0);
    }

    /**
     * @param goodsUpdate
     * @return
     */
    public Integer updateGoodsNullByGoodsId(Goods goodsUpdate) {

        Integer row = goodsMapper.updateGoodsNullByGoodsId(goodsUpdate);
        return row;
    }

    /**
     * 清空PKG_id
     *
     * @param goods
     * @return
     */
    public Integer updateGoodsDePackage(Goods goods) {

        Integer row = goodsMapper.updateGoodsDePackage(goods);
        return row;
    }

    public List<GoodsTemp> selectGoodsTempListByListSn(List<String> listSn) {
        if (listSn != null && listSn.size() > 0) {
            QueryWrapper<GoodsTemp> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("GOODS_SN", listSn);
            List<GoodsTemp> items = this.goodsTempMapper.selectList(queryWrapper);
            return items;
        }
        return new ArrayList<GoodsTemp>(0);
    }

    /**
     * 根据条码更新状态
     * @param waitDowmCode
     * @param goodsSnList
     * @param loginName
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer updateStatusByGoodsList(int waitDowmCode, List<String> goodsSnList,String loginName) {
        //创建类型的条件构造器
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.in("GOODS_SN",goodsSnList);

        Goods goods = new Goods();
        goods.setModifyTime(new Date());
        goods.setModifyUser(loginName);
        goods.setStatus(waitDowmCode);

        int update = goodsMapper.update(goods, wrapper);
        return update;
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer updateGoodsSetLocNull(Goods goodsUpdate) {
        Integer row = goodsMapper.updateGoodsSetLocNull(goodsUpdate);
        return row;
    }
    
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer updateLocIdAndPkgIdAndStatusById(Goods goodsUpdate) {
        Integer row = goodsMapper.updateLocIdAndPkgIdAndStatusById(goodsUpdate);
        return row;
    }
    
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer updateLocIdAndStatusById(Goods goodsUpdate) {
        Integer row = goodsMapper.updateLocIdAndStatusById(goodsUpdate);
        return row;
    }
    
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer updateWhsIdAndLocIdAndStatusById(Goods goodsUpdate) {
        Integer row = goodsMapper.updateWhsIdAndLocIdAndStatusById(goodsUpdate);
        return row;
    }



}